package com.imooc.dataobject.mapper;

import com.imooc.dataobject.ProductCategory;
import lombok.Data;
import org.apache.ibatis.annotations.*;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * 类目
 * Created by 廖师兄
 * 2017-05-07 14:30
 */
//@Mapper
public interface ProductCategoryMapper {
    @Insert("insert into product_category(category_name,category_type) values( #{categoryName,jdbcType=VARCHAR},#{categoryType,jdbcType=INTEGER})")
    int insertByMap(Map<String,Object> map);
    
    
    @Insert("insert into product_category(category_name,category_type) values( #{categoryName,jdbcType=VARCHAR},#{categoryType,jdbcType=INTEGER})")
    int insertObject(ProductCategory productCategory);
    
    @Select("select * from product_category where category_type = #{categoryType}")
    @Results({
            @Result(column ="category_id",property = "categoryId"),
            @Result(column ="category_type",property = "categoryType"),
            @Result(column ="category_name",property = "categoryName")
    })
    ProductCategory findByCategoryType(Integer categoryType);
    
    
    @Select("select * from product_category where category_name = #{categoryName}")
    @Results({
            @Result(column ="category_id",property = "categoryId"),
            @Result(column ="category_type",property = "categoryType"),
            @Result(column ="category_name",property = "categoryName")
    })
    List<ProductCategory> findByCategoryName(String categoryName);
    
    
    @Update("update product_category set category_name = #{categoryName} where category_type=#{categoryType}")
    int updateByObject(ProductCategory productCategory);
    
    
    
    @Update("update product_category set category_name = #{categoryName} where category_type=#{categoryType}")
    int updateByCategoryType(@Param("categoryName") String categoryName,
                             @Param("categoryType")Integer categoryType);
    
    
    @Delete("delete from product_category where category_type=#{categoryType}")
    int deleteByCategoryType(Integer categoryType);
    
    
    // 测试 xml方式
    ProductCategory selectByCategoryType(Integer categoryType);
    
    
}
